/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package control;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import model.AgendaDAO;
import model.Compromisso;
import model.CompromissoDAO;
import model.PacienteDAO;

/**
 *
 * @author Eduarda
 */
public class TrataEditarCompromisso extends Comando {

    @Override
    public void executar(HttpServletRequest request, HttpServletResponse response) throws ClassNotFoundException, SQLException, IOException, ServletException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        try {
            response.setContentType("text/html");
            
            
            String idEditar = request.getParameter("idEditar");
            PacienteDAO pacdao = new PacienteDAO();
        AgendaDAO agendao = new AgendaDAO();
            Compromisso com = new CompromissoDAO().pesquisarById(idEditar);
            HttpSession session = request.getSession(false);
            session.setAttribute("com2", com);
           session.setAttribute("listaPacientes", pacdao.pesquisar());
            session.setAttribute("listaAgendas", agendao.pesquisar());    
            //Redireciona para outra página
            response.sendRedirect("editarCompromisso.jsp");
        } catch (IOException ioex) {
            throw new ServletException(ioex);
        } catch(SQLException sqlex){
              throw new ServletException (sqlex);
        }
    }
    
}
